package com.cspg.ssss.config;

import com.cspg.ssss.job.*;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class QuartzConfig {
    @Bean
    public JobDetail sendMsgTaskDetail() {
        return JobBuilder.newJob(SendMsgJob.class).withIdentity("SendMsgJob").storeDurably().build();
    }

    @Bean
    public Trigger sendMsgTaskTrigger() {
        CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule("0 30 8 * * ?");
        return TriggerBuilder.newTrigger().forJob(sendMsgTaskDetail())
                .withIdentity("SendMsgJob")
                .withSchedule(scheduleBuilder)
                .build();
    }

    @Bean
    public JobDetail daiBanTaskDetail() {
        return JobBuilder.newJob(DaiBanJob.class).withIdentity("DaiBanJob").storeDurably().build();
    }

    @Bean
    public Trigger daiBanTaskTrigger() {
        CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule("0 0/5 * * * ?");
        return TriggerBuilder.newTrigger().forJob(daiBanTaskDetail())
                .withIdentity("DaiBanJob")
                .withSchedule(scheduleBuilder)
                .build();
    }


    @Bean
    public JobDetail securityRiskJobDetail() {
        return JobBuilder.newJob(SecurityRiskJob.class).withIdentity("SecurityRiskJob").storeDurably().build();
    }

    @Bean
    public Trigger securityRiskTrigger() {
        CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule("0 0 1 1 1,4,7,10 ?");
        return TriggerBuilder.newTrigger().forJob(securityRiskJobDetail())
                .withIdentity("SecurityRiskJob")
                .withSchedule(scheduleBuilder)
                .build();
    }

    @Bean
    public JobDetail userJobDetail() {
        return JobBuilder.newJob(SyncUserJob.class).withIdentity("SyncUserJob").storeDurably().build();
    }

    @Bean
    public Trigger syncUserTrigger() {
        CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule("0 0 2 * * ?");
        return TriggerBuilder.newTrigger().forJob(userJobDetail())
                .withIdentity("SyncUserJob")
                .withSchedule(scheduleBuilder)
                .build();
    }

    @Bean
    public JobDetail scoreStatisticsTaskDetail() {
        return JobBuilder.newJob(ScoreStatisticsJob.class).withIdentity("ScoreStatisticsJob").storeDurably().build();
    }

    @Bean
    public Trigger scoreStatisticsTrigger() {
        CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule("0 0 0 * * ?");
        return TriggerBuilder.newTrigger().forJob(scoreStatisticsTaskDetail())
                .withIdentity("ScoreStatisticsJob")
                .withSchedule(scheduleBuilder)
                .build();
    }

    @Bean
    public JobDetail syncProblemTask() {
        return JobBuilder.newJob(SyncProblemJob.class).withIdentity("SyncProblemJob").storeDurably().build();
    }

    @Bean
    public Trigger syncProblemTaskTrigger() {
        CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule("0 0/20 * * * ?");
        return TriggerBuilder.newTrigger().forJob(syncProblemTask())
                .withIdentity("SyncProblemJob")
                .withSchedule(scheduleBuilder)
                .build();
    }

    @Bean
    public JobDetail dailyTask() {
        return JobBuilder.newJob(DailyJob.class).withIdentity("DailyJob").storeDurably().build();
    }

    @Bean
    public Trigger dailyTaskTrigger() {
        CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule("0 0 4 * * ?");
        return TriggerBuilder.newTrigger().forJob(dailyTask())
                .withIdentity("DailyJob")
                .withSchedule(scheduleBuilder)
                .build();
    }


}
